<template>
    <div class="edu-page-warp">
        <ConditionCard
            shadow="never"
            body-style="padding: 24px 24px 6px 24px;"
            @search="onSubmit"
            @reset="reset"
        >
            <el-form :model="queryForm" label-position="right" label-width="80px">
                <el-row :gutter="24" style="height: 50px;">
                    <el-col :span="8">
                        <el-form-item :label="$t('label.grade')+':'">
                            <el-select v-model="queryForm.grade" style="width: 100%;"
                            clearable>
                                <el-option
                                    v-for="item in options.grade"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.enrolSeason')+':'">
                            <el-select v-model="queryForm.term" style="width: 100%;"
                            clearable>
                                <el-option
                                    v-for="item in options.term"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.trainingLevel')+':'">
                            <el-select v-model="queryForm.trainingLevel" style="width: 100%;"
                            clearable>
                                <el-option
                                    v-for="item in options.trainingLevel"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <template v-if="queryForm.projId == 1">
                        <el-col :span="8">
                            <el-form-item :label="$t('message.startTime')+':'">
                                <el-date-picker
                                    style="width: 100%;"
                                    v-model="queryForm.startTime"
                                    type="date"
                                    placeholder="选择日期"
                                    clearable
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </template>
                    <template v-else>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.trainingCategory')+':'">
                                <el-select v-model="queryForm.trainingCategory" style="width: 100%;"
                                clearable>
                                    <el-option
                                        v-for="item in options.trainingCategory"
                                        :key="item.code"
                                        :label="item.name"
                                        :value="item.code"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </template>
                    <template v-if="queryForm.projId == 1">
                        <el-col :span="8">
                            <el-form-item :label="$t('message.endTime')+':'">
                                <el-date-picker
                                    style="width: 100%;"
                                    v-model="queryForm.endTime"
                                    type="date"
                                    placeholder="选择日期"

                                    clearable
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </template>
                    <template v-else>
                        <el-col :span="8">
                            <el-form-item :label="$t('culturePlan.degreeType')+':'">
                                <el-select v-model="queryForm.degreeType" style="width: 100%;"
                                clearable>
                                    <el-option
                                        v-for="item in options.degreeType"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.formLearning')+':'">
                                <el-select v-model="queryForm.formLearning" style="width: 100%;"
                                clearable>
                                    <el-option
                                        v-for="item in options.formLearning"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </template>
                </el-row>
            </el-form>
        </ConditionCard>
        <el-card shadow="never" body-style="padding: 24px;" class="card-margin">
            <h1 class="condition-title">培养计划权限</h1>
            <div class="div-main clearfix">
                <div class="float-right">
                    <el-button @click="showDeleteDialog">{{$t("message.delete")}}</el-button>
                    <el-button @click="showAddDialog" type="primary">{{$t("message.add") + $t("culturePlan.planOpenAuthority")}}</el-button>
                </div>
            </div>
            <el-table stripe :data="data" size="mini" @selection-change="chooseRow" tooltip-effect="light">
                <el-table-column type="expand">
                    <template slot-scope="props">
                        <el-form label-position="left" label-width="100px">
                            <el-row :gutter="24" style="height: 50px;">
                                <el-col :span="8">
                                    <el-form-item :label="$t('label.grade')">{{props.row.grade}}</el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item :label="$t('label.enrolSeason')">{{props.row.termI18n}}</el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item :label="$t('label.trainingLevel')" >{{props.row.trainingLevel}}</el-form-item>
                                </el-col>
                            </el-row>
                            <el-row :gutter="24" style="height: 50px;">
                                
                                    <el-col :span="8">
                                        <el-form-item :label="$t('message.startDate')" >{{props.row.startTime}}</el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item :label="$t('message.endDate')" >{{props.row.endTime}}</el-form-item>
                                    </el-col>
                                
                                <template v-if="queryForm.projId == 2">
                                    <el-col :span="8">
                                        <el-form-item :label="$t('label.trainingCategory')" >{{props.row.trainingCategory}}</el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item :label="$t('culturePlan.degreeType')" >{{props.row.degreeType}}</el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item :label="$t('label.formLearning')" >{{props.row.formLearning}}</el-form-item>
                                    </el-col>
                                </template>
                            </el-row>
                            <template v-if="queryForm.projId == 1">
                                <el-row :gutter="24">
                                    <el-col :span="24">
                                        <el-form-item :label="$t('label.college')">{{props.row.college}}</el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="24">
                                    <el-col :span="24">
                                        <el-form-item :label="$t('label.major')">{{props.row.major}}</el-form-item>
                                    </el-col>
                                </el-row>
                            </template>
                            <template v-else>
                                <el-row :gutter="24">
                                    <el-col :span="8">
                                        <el-form-item :label="$t('culturePlan.courseApprove')">{{props.row.courseApproveI18n}}</el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item :label="$t('culturePlan.planMaintain')">{{props.row.planMaintainI18n}}</el-form-item>
                                    </el-col>
                                </el-row>
                            </template>
                            <el-row :gutter="24" style="height: 50px;">
                                <el-col :span="24">
                                    <el-form-item :label="$t('label.college')">
                                        <div :style="{'overflow-wrap': 'break-word'}">
                                            {{props.row.facultyI18n}}
                                        </div>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                    </template>
                </el-table-column>
                <el-table-column type="selection" width="30"></el-table-column>
                <el-table-column prop="grade" :label="$t('label.grade')" width="70"></el-table-column>
                <el-table-column :label="$t('label.college')" show-overflow-tooltip prop="facultyI18n" />
                <el-table-column prop="termI18n" :label="$t('label.enrolSeason')" width="85"></el-table-column>
                <el-table-column :label="$t('label.trainingLevel')" min-width="100" show-overflow-tooltip>
                    <template slot-scope="scope">
                             
                           {{scope.row.trainingLevel}}
                            
                        </template>
                </el-table-column>
                <template v-if="queryForm.projId == 1">
                    <el-table-column prop="startTime" :label="$t('message.startTime')"></el-table-column>
                    <el-table-column prop="endTime" :label="$t('message.endTime')"></el-table-column>
                </template>
                <template v-else>
                    <el-table-column :label="$t('label.trainingCategory')" min-width="120" show-overflow-tooltip>
                        <template slot-scope="scope">
                            {{scope.row.trainingCategory}}
                        </template>
                    </el-table-column>
                    <el-table-column :label="$t('culturePlan.degreeType')" min-width="100" show-overflow-tooltip>
                        <template slot-scope="scope">
                             {{scope.row.degreeType}}   
                        </template>
                    </el-table-column>
                    <el-table-column :label="$t('label.formLearning')" min-width="100" show-overflow-tooltip>
                         <template slot-scope="scope">
                            {{scope.row.formLearning}}     
                        </template>
                    </el-table-column>
                     <el-table-column :label="$t('message.startTime')" min-width="160">
                            <template slot-scope="scope">
                             {{scope.row.startTime}}   
                        </template>
                     </el-table-column>
                    <el-table-column :label="$t('message.endTime')"  min-width="160">
                            <template slot-scope="scope">
                             {{scope.row.endTime}}   
                        </template>
                    </el-table-column>
                    <el-table-column :label="$t('culturePlan.courseApprove')" width="100">
                        <template slot-scope="scope" v-if="scope.row.courseApprove">
                            <el-tag :type="scope.row.courseApprove == 1 ? 'success' : 'danger'">
                            {{ scope.row.courseApproveI18n }}
                            </el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column :label="$t('culturePlan.planMaintain')" width="110">
                        <template slot-scope="scope" v-if="scope.row.planMaintain">
                            <el-tag :type="scope.row.planMaintain == 1 ? 'success' : 'danger'">
                            {{ scope.row.planMaintainI18n }}
                            </el-tag>
                        </template>
                    </el-table-column>
                </template>
                <el-table-column :label="$t('message.operating')" width="100">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            @click="editPermission(scope.row)"
                            size="mini"
                        >{{$t("message.edit")}}</el-button>
                        <el-button
                            type="text"
                            @click="deletePermission(scope.row)"
                            size="mini"
                        >{{$t("message.delete")}}</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="edu-pagination">
                <div class="float-right">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="queryForm.pageNum_"
                        :page-sizes="[20,50,100,500,1000]"
                        :page-size="queryForm.pageSize_"
                        :total="queryForm.total_"
                        layout="total, sizes, prev, pager, next, jumper"
                        style="float: right;margin:10px 60px 0 0;"
                    />
                </div>
            </div>
        </el-card>
        <el-dialog
            :title="dialogTitle"
            width="70%"
            :visible.sync="showDialog"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
        >
            <el-form
                :model="postForm"
                label-position="right"
                label-width="100px"
                ref="postForm"
                :rules="rules"
            >
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('label.grade')" prop="grade">
                            <el-select   v-model="postForm.grade" style="width: 100%;" multiple collapse-tags>
                                <el-option
                                    v-for="item in options.grade"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.enrolSeason')" prop="term">
                            <el-select v-model="postForm.term" style="width: 100%;">
                                <el-option
                                    v-for="item in options.term"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.trainingLevel')" prop="trainingLevel">
                            <el-select   v-model="postForm.trainingLevel" style="width: 100%;"
                            multiple collapse-tags
                           >
                                <el-option
                                    v-for="item in options.trainingLevel"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <template v-if="queryForm.projId == 1">
                        <el-col :span="8">
                            <el-form-item label="限制选课" prop="relationSelectCourse">
                                <el-select v-model="postForm.relationSelectCourse" style="width: 100%;">
                                    <el-option
                                        v-for="item in options.relationSelectCourse"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('message.startDate')" prop="startTime">
                                <el-date-picker
                                    style="width: 100%;"
                                    v-model="postForm.startTime"
                                    type="date"
                                    placeholder="选择日期"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('message.endDate')" prop="endTime">
                                <el-date-picker
                                    style="width: 100%;"
                                    v-model="postForm.endTime"
                                    type="date"
                                    placeholder="选择日期"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </template>
                    <template v-else>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.trainingCategory')">
                                <el-select v-model="postForm.trainingCategory" style="width: 100%;" 
                                clearable   multiple collapse-tags>
                                    <el-option
                                        v-for="item in options.trainingCategory"
                                        :key="item.code"
                                        :label="item.name"
                                        :value="item.code"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('culturePlan.degreeType')">
                                <el-select v-model="postForm.degreeType" style="width: 100%;"
                                clearable multiple collapse-tags>
                                    <el-option
                                        v-for="item in options.degreeType"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.formLearning')">
                                <el-select v-model="postForm.formLearning" style="width: 100%;"
                                clearable multiple collapse-tags>
                                    <el-option
                                        v-for="item in options.formLearning"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </template>
                </el-row>
                <template v-if="queryForm.projId == 1">
                    <el-row :gutter="24">
                        <el-col :span="24">
                            <el-transfer
                                ref="transfer1"
                                style="margin-bottom:10px"
                                v-model="selectedColleges"
                                :data="initColleges"
                                :titles="collegeTitle"
                                @change="getMajorsByColleges"
                                key="transfer1"
                            ></el-transfer>
                        </el-col>
                        <el-col :span="24">
                            <el-transfer
                                ref="transfer2"
                                v-model="selectedMajors"
                                :data="initMajors"
                                :titles="majorTitle"
                                key="transfer2"
                            ></el-transfer>
                        </el-col>
                    </el-row>
                </template>
                <template v-else>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('culturePlan.courseApprove')" prop="courseApprove">
                                <el-select v-model="postForm.courseApprove" style="width: 100%;"
                                clearable>
                                    <el-option
                                        v-for="item in options.courseApprove"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('culturePlan.planMaintain')"  prop="planMaintain">
                                <el-select v-model="postForm.planMaintain" style="width: 100%;"
                                clearable>
                                    <el-option
                                        v-for="item in options.planMaintain"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.college')" prop="faculty">
                                <el-select
                                    v-model="postForm.faculty"
                                    style="width: 100%"
                                    collapse-tags
                                    @change="changeFaculty"
                                    multiple
                                >
                                    <el-option
                                        v-for="item in options.faculty"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('message.startDate')" prop="startTime">
                                <el-date-picker
                                    style="width: 100%;"
                                    v-model="postForm.startTime"
                                    type="datetime"
                                    placeholder="选择日期"
                                    :picker-options="pickerBeginDateBefore"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('message.endDate')" prop="endTime">
                                <el-date-picker
                                    style="width: 100%;"
                                    v-model="postForm.endTime"
                                    type="datetime"
                                    placeholder="选择日期"
                                    :picker-options="pickerBeginDateAfter"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </template>
                <el-row :gutter="24">
                    <el-col :span="24" style="text-align:right;margin-top:10px">
                        <el-button @click="cancel" type="button">{{$t('message.cancel')}}</el-button>
                        <el-button @click="save" type="primary">{{$t('message.save')}}</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>
    </div>
</template>
<script>
import bus from "common/src/utils/bus";
import { queryDic, findTrainingLevelByProjId, sortTrainingCategories } from "common/src/api/dictionary";
import { findFaculty } from "common/src/api/faculty";
import { queryList } from "common/src/api/culture/culturePlan";
import UTILS from "common/src/utils/utils";
import {
    addAuthPushTime,
    findAuthPushTimePermissionPage,
    deleteAuthPushTimeByIds,
    findAuthPushTimeById,
    updateAuthPushTime
} from "common/src/api/user";
import {
    getAuthPushTimeListPage,
    getAuthPushTimeById,
    addAuthTime,
    updateAuthTime,
    deleteAuthTimeByIds
} from "common/src/api/culture/cultureAuth";
export default {
    name: "permission",
    components: {},
    data() {
        return {
            queryForm: {
                grade: "",
                trainingLevel: "",
                trainingCategory: "",
                degreeType: "",
                formLearning: "",
                term: "",
                startTime: "",
                endTime: "",
                pageSize_: 20,
                pageNum_: 1,
                total_: 0
            },
            postForm: {
                id: '',
                grade: "",
                trainingLevel:"",
                trainingCategory: "",
                degreeType: "",
                formLearning: "",
                courseApprove: "",
                planMaintain: "",
                term: "",
                startTime: "",
                endTime: "",
                relationSelectCourse: "",
                faculty: []
            },
            options: {
                grade: [],
                trainingLevel: [],
                trainingCategory: [],
                degreeType: [],
                formLearning: [],
                courseApprove: [],
                planMaintain: [],
                term: [],
                college: [],
                relationSelectCourse: [],
                faculty: []
            },
            collegeTitle: ["所有学院", "已选学院"],
            majorTitle: ["所有专业", "已选专业"],
            data: null,
            chooseRows: [], //选中行
            showDialog: false,
            initColleges: [],
            initMajors: [],
            selectedColleges: [],
            selectedMajors: [],
            dialogTitle: "",
            showTerm: true,
            pickerBeginDateBefore: {
              disabledDate: (time) => {
                    let endDateVal = this.postForm.endTime;
                        if (endDateVal) {
                            return time.getTime() < new Date(endDateVal).getTime() - 180 * 24 * 60 * 60 * 1000 || time.getTime() > new Date(endDateVal).getTime()
                          }
                       }
                     },
            pickerBeginDateAfter: {
              disabledDate: (time) => {
                   let beginDateVal = this.postForm.startTime;
                    if (beginDateVal) {
                      return time.getTime() > new Date(beginDateVal).getTime() + 180 * 24 * 60 * 60 * 1000 || time.getTime() < new Date(beginDateVal).getTime()
                       }
                   }
                },
            rules: {
                grade: [
                    {
                        required: true,
                        message: "请选择年级",
                        trigger: "change"
                    }
                ],
                trainingLevel: [
                    {
                        required: true,
                        message: "请选择培养层次",
                        trigger: "change"
                    }
                ],
                term: [
                    {
                        required: true,
                        message: "请选择入学季节",
                        trigger: "blur"
                    }
                ],
                relationSelectCourse: [
                    {
                        required: true,
                        message: "请选择是否关联选课",
                        trigger: "blur"
                    }
                ],
                startTime: [
                    {
                        required: true,
                        message: "请选择开始时间",
                        trigger: "change"
                    }
                ],
                endTime: [
                    {
                        required: true,
                        message: "请选择结束时间",
                        trigger: "change"
                    }
                ],
                courseApprove: [
                    {
                        required: true,
                        message: "请选择选课审批",
                        trigger: "change"
                    }
                ],
                planMaintain: [
                    {
                        required: true,
                        message: "请选择是否维护",
                        trigger: "change"
                    }
                ]
            }
        };
    },
    mounted: function() {
        this.init();
        this.initProjId();
        this.initTrainingLevelOptions();
    },
    methods: {
     
        initProjId() {
            let currentUser =
                (this.$store.state.session && this.$store.state.session.user) ||
                JSON.parse(localStorage.getItem("user"));
            this.queryForm.projId = currentUser.currentManageDptId;
            this.onSubmit();
        },
        initTrainingLevelOptions() {
            findTrainingLevelByProjId(this.queryForm.projId).then(res => {
                if (res.code === 200) {
                    this.queryForm.trainingLevel = "";
                    this.loadTrainingLevelOptions("trainingLevel", res.data);
                }
            });
        },
        loadTrainingLevelOptions(optionKey, dataObj) {
            this.options[optionKey] = [];
            _.each(dataObj, level => {
                this.options[optionKey].push({
                    label:
                        "en" === this.$store.getters.language
                            ? level.nameEN
                            : level.nameCN,
                    value: level.code
                });
            });
        },
        init() {
            //关联选课
            this.options.relationSelectCourse.push({ label: this.$t("message.yes"), value: "1" });
            this.options.relationSelectCourse.push({ label: this.$t("message.no"), value: "0" });
            
            //绑定年级
            let now = new Date();
            let currentYear = now.getFullYear(),
                minYear = currentYear - 10;
            for (let grade = currentYear + 1; grade > minYear; grade--) {
                let obj = { label: String(grade), value: String(grade) };
                this.options.grade.push(obj);
            }
            
            findFaculty().then(res => { 
                let data = {"X_YX": res.data};
                UTILS.fillSelect({ college: "X_YX" }, data, this.options);
                this.options.faculty = [
                    {
                        key: 'all',
                        value: 'all',
                        label: '全部'
                    }, 
                    ...this.options.college
                ];
            });
            let data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["X_PYLB", "X_XWLX", "K_XXXS", "X_RXJJ", "K_XKSP", "K_JHWH"]
            };
            queryDic(data).then(res => {
                let params = {
                        lang: this.$store.getters.language,
                        keys: ["X_PYLB"]
                    };
                    sortTrainingCategories(params).then((res) => {
                        this.options.trainingCategory = res.data.X_PYLB;
                    });
                if (res.code == 200) {
                    UTILS.fillSelect(
                        {
                            // trainingCategory: "X_PYLB",
                            degreeType: "X_XWLX",
                            formLearning: "K_XXXS",
                            term: "X_RXJJ",
                            courseApprove: "K_XKSP",
                            planMaintain: "K_JHWH"
                        },
                        res.data,
                        this.options
                    );
                }
            });
        },
        reset() {
            this.queryForm.grade = "";
            this.queryForm.trainingLevel = "";
            this.queryForm.trainingCategory = "";
            this.queryForm.degreeType = "";
            this.queryForm.formLearning = "";
            this.queryForm.term = "";
            this.queryForm.startTime = "";
            this.queryForm.endTime = "";
            this.onSubmit();
        },
        onSubmit(isFirstPage = true) {
            console.log(1)
            if (isFirstPage) {
                this.queryForm.pageNum_ = 1;
            }
            let data = _.cloneDeep(this.queryForm);
            if(this.queryForm.projId == 1) {
                 // 本科
                if (this.queryForm.startTime)
                    data.startTime = this.queryForm.startTime.getTime();
                if (this.queryForm.endTime)
                    data.endTime = this.queryForm.endTime.getTime();
                findAuthPushTimePermissionPage(data).then(res => {
                    if (res.code == 200) {
                        res.data.list.forEach(row => {
                            //处理时间
                            if (row.startTime) {
                                let start = new Date();
                                start.setTime(row.startTime);
                                row.startTime = start.toLocaleString();
                            }
                            if (row.endTime) {
                                let end = new Date();
                                end.setTime(row.endTime);
                                row.endTime = end.toLocaleString();
                            }
                            let content = JSON.parse(row.content);
                            //转换学院
                            if (content.isAllCollege) {
                                row.college = "全部";
                            } else {
                                row.college = content.college
                                    .map((c, index) => index + 1 + "." + c.label)
                                    .join("，");
                            }
                            //转换专业
                            if (content.isAllMajor) {
                                row.major = "全部";
                            } else {
                                row.major = content.major
                                    .map((c, index) => index + 1 + "." + c.label)
                                    .join("，");
                            }
                            let term = this.options.term.find(
                                t => t.value == content.term
                            );
                            row.trainingLevelI18n = row.trainingLevel
                            row.term = term ? term.value : "";
                            row.termI18n = term ? term.label : "";
                        });
                        this.data = res.data.list;
                        this.queryForm.total_ = res.data.total_;
                    }
                });
            } else {
                getAuthPushTimeListPage(data).then(res => {
                    if (res.code == 200) {
                        res.data.list.forEach(row =>{   
                            row.trainingCategory=row.trainingCategory ? row.trainingCategory.split(","):[]; 
                            var arry=[];
                            row.trainingCategory.forEach(t=>{
                                   if(t==1){
                                         arry.push("学位生")
                                   }
                                   if(t==2){
                                         arry.push("双学位生")
                                   }
                                  if(t==3){
                                         arry.push("学历学位生")
                                   }
                                   if(t==4){
                                         arry.push("旁听生")
                                   }
                                   if(t==5){
                                         arry.push("借读生")
                                   }
                                   if(t==6){
                                         arry.push("课程进修生")
                                   }
                                   if(t==7){
                                         arry.push("研修生")
                                   }
                                   if(t==8){
                                         arry.push("直博生")
                                   }        
                            });
                            row.trainingCategory=arry.join(',');
                            
                            row.degreeType=row.degreeType ? row.degreeType.split(","):[]; 
                            var arry1=[];
                            row.degreeType.forEach(d=>{
                                 if(d==1){
                                         arry1.push("学术型")
                                   }
                                 if(d==2){
                                         arry1.push("专业型")
                                   }
                                 if(d==3){
                                         arry1.push("无学位")
                                   } 
                                 if(d==4){
                                         arry1.push("全部")
                                   } 
                           
                            });
                            row.degreeType=arry1.join(',');
                             var arry2=[];
                            row.formLearning=row.formLearning ? row.formLearning.split(","):[];
                            row.formLearning.forEach(f=>{
                                if(f==1){
                                         arry2.push("全日制")
                                   }
                                 if(f==2){
                                         arry2.push("非全日制")
                                   }
                                 if(f==4){
                                         arry2.push("全部")
                                   } 
                            });
                            row.formLearning=arry2.join(',')
                            row.trainingLevel=row.trainingLevel ? row.trainingLevel.split(","):[];
                            var arry3=[];
                            row.trainingLevel.forEach(tr=>{
                                 if(tr==4){
                                         arry3.push("硕士")
                                   }
                                 if(tr==6){
                                         arry3.push("博士")
                                   }
                            });
                          row.trainingLevel=arry3.join(',');
                          //处理时间
                        if (row.startTime) {
                            let startTime = new Date(row.startTime);
                            let y = startTime.getFullYear(),
                         　     m = startTime.getMonth() + 1,
                        　　    d = startTime.getDate();
                         　row.startTime = y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + startTime.toTimeString().substr(0, 8);
                           
                        }
                        if (row.endTime) {
                            let endTime = new Date(row.endTime);
                            let y = endTime.getFullYear(),
                         　　   m = endTime.getMonth() + 1,
                        　　    d = endTime.getDate();
                         　　row.endTime = y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + endTime.toTimeString().substr(0, 8);
                        } 
                            });
                             
                        this.data = res.data.list;
                        this.queryForm.total_ = res.data.total_;
                    }
                });
            }
            
        },
        handleSizeChange(val) {
            this.queryForm.pageSize_ = val;
            this.onSubmit();
        },
        handleCurrentChange(val) {
            this.queryForm.pageNum_ = val;
            this.onSubmit(false);
        },
        //编辑权限
        editPermission(row) {
            this.initDialog();
            this.dialogTitle = this.$t('message.edit') + this.$t('culturePlan.planOpenAuthority');
            this.postForm.id = row.id;
            if(this.queryForm.projId == 1) { // 本科 
                findAuthPushTimeById("id=" + row.id).then(res => {
                    if (res.code == 200) {
                        this.postForm.grade = res.data.grade;
                        this.postForm.trainingLevel = res.data.trainingLevel;
                        this.postForm.formLearning = res.data.formLearning;
                        this.postForm.startTime = res.data.startTime;
                        this.postForm.endTime = res.data.endTime;
                        let content = JSON.parse(res.data.content);
                        this.selectedColleges = content.college.map(c => c.value);
                        this.initMajors = content.leftMajor;
                        this.selectedMajors = content.major.map(c => c.value);
                        //关联选课
                        if (content.relationSelectCourse) {
                            this.postForm.relationSelectCourse =
                                content.relationSelectCourse;
                        }
                        //是否显示入学季节
                        if (
                            res.data.trainingLevel != 4 &&
                            res.data.trainingLevel != 6
                        ) {
                            this.showTerm = false;
                        } else {
                            this.postForm.term = content.term;
                        }
                        if (res.data.startTime) {
                            let startTime = new Date();
                            startTime.setTime(res.data.startTime);
                            this.postForm.startTime = startTime;
                        }
                        if (res.data.endTime) {
                            let endTime = new Date();
                            endTime.setTime(res.data.endTime);
                            this.postForm.endTime = endTime;
                        }
                    }
                });
            } else {
                getAuthPushTimeById("id=" + row.id).then(res => {
                    if (res.code == 200) {
                        this.postForm.grade = res.data.grade? res.data.grade.split(","):[];
                        this.postForm.trainingLevel = res.data.trainingLevel ? res.data.trainingLevel.split(","):[];
                        this.postForm.trainingCategory = res.data.trainingCategory ? res.data.trainingCategory.split(","):[];
                        this.postForm.degreeType = res.data.degreeType ? res.data.degreeType.split(","):[];
                        this.postForm.formLearning = res.data.formLearning ? res.data.formLearning.split(","):[];
                        this.postForm.courseApprove = res.data.courseApprove;
                        this.postForm.planMaintain = res.data.planMaintain;
                        this.postForm.term = res.data.term;
                        let facultyPer = res.data.faculty || row.faculty || '';
                        this.postForm.faculty = facultyPer && facultyPer.split(',') || [];
                         if (res.data.startTime) {
                            let startTime = new Date();
                            startTime.setTime(res.data.startTime);
                            this.postForm.startTime = startTime;
                        }
                        if (res.data.endTime) {
                            let endTime = new Date();
                            endTime.setTime(res.data.endTime);
                            this.postForm.endTime = endTime;
                        }
                        if (res.data.trainingLevel != 4 && res.data.trainingLevel != 6 ) {
                            this.showTerm = false;
                        }
                    }
                });
            }
        },
        //删除权限
        deletePermission(row) {
            this.$confirm("是否确认删除?", this.$t("message.prompt"), {
                confirmButtonText: this.$t("message.confirm"),
                cancelButtonText: this.$t("message.cancel"),
                type: "warning"
            }).then(() => {
                if(this.queryForm.projId == 1) { // 本科 
                    deleteAuthPushTimeByIds([row.id]).then(res => {
                        if (res.code == 200) {
                            this.onSubmit();
                        }
                    });
                } else {
                    deleteAuthTimeByIds([row.id]).then(res => {
                        if (res.code == 200) {
                            this.onSubmit();
                        }
                    });
                }
            }).catch(e => {});
        },
        //表格复选框选中或取消
        chooseRow(val) {
            this.chooseRows = val;
        },
        showDeleteDialog() {
            if (this.chooseRows.length == 0) {
                this.$message({
                    type: "info",
                    message: "请选择要删除的权限"
                });
                return;
            }
            this.$confirm("是否确认删除?", this.$t("message.prompt"), {
                confirmButtonText: this.$t("message.confirm"),
                cancelButtonText: this.$t("message.cancel"),
                type: "warning"
            }).then(() => {
                let ids = this.chooseRows.map(c => c.id);
                if(this.queryForm.projId == 1) { // 本科 
                    deleteAuthPushTimeByIds(ids).then(res => {
                        if (res.code == 200) {
                            this.onSubmit();
                        }
                    });
                } else {
                    deleteAuthTimeByIds(ids).then(res => {
                        if (res.code == 200) {
                            this.onSubmit();
                        }
                    });
                }
            }).catch(e => {});
        },
        showAddDialog() {
            this.initDialog();
            console.log(this.postForm.trainingCategory);
            this.dialogTitle = this.$t('message.add') + this.$t('culturePlan.planOpenAuthority');
            this.postForm.id = "";
        },
        initDialog() {
            this.showTerm = true;
            this.postForm.id = "";
            
            this.postForm.trainingLevel = [];
            if(this.queryForm.projId == 1) { // 本科保留原状
                this.postForm.startTime = "";
                this.postForm.endTime = "";
                this.postForm.relationSelectCourse = "";
                 this.postForm.grade = "";
                this.initColleges = this.options.college.map(c => {
                    return { key: c.value, label: c.label };
                });
                if (this.$refs.transfer1)
                    this.$refs.transfer1.leftChecked.length = 0;
                this.selectedColleges = [];
                this.initMajors = [];
                this.selectedMajors = [];
            } else {
                this.postForm.grade = [];
                this.postForm.trainingCategory =[];
                this.postForm.degreeType = [];
                this.postForm.formLearning = [];
                this.postForm.courseApprove = "";
                this.postForm.planMaintain = "";
                this.postForm.term = "";
            }
            
            if (this.$refs.postForm) this.$refs.postForm.resetFields();
            this.showDialog = true;
        },
        //取消保存
        cancel() {
            this.showDialog = false;
        },
        //保存权限
        save() {
            this.$refs.postForm.validate(valid => {
                if (!valid) {
                    return;
                }
                
                let data = {
                    id: this.postForm.id,
                    grade: this.postForm.grade,
                    projId: this.queryForm.projId,
                    //trainingLevel: this.postForm.trainingLevel,
                    startTime:this.postForm.startTime,
                    endTime: this.postForm.endTime

                }
                
                let fn = res => {
                    if (res.code == 200) {
                        this.showDialog = false;
                        this.onSubmit();
                    }
                };
                
                if(this.queryForm.projId == 1) { // 本科保留原状
                    data.auth = [231], //authId为231，培养计划权限Id
                    data.startTime = this.postForm.startTime ? this.postForm.startTime.getTime() : ""
                    data.endTime = this.postForm.endTime ? this.postForm.endTime.getTime() : ""
                    let college = [];
                    this.selectedColleges.forEach(c => {
                        let option = this.initColleges.find(c_ => c_.key == c);
                        if (option) {
                            college.push({ label: option.label, value: c });
                        }
                    });
                    let major = [];
                    this.selectedMajors.forEach(m => {
                        let option = this.initMajors.find(m_ => m_.key == m);
                        if (option) {
                            major.push({ label: option.label, value: m });
                        }
                    });
                    data.content = JSON.stringify({
                        type: "culturePlanPermission",
                        isAllCollege:
                            this.selectedColleges.length ==
                            this.initColleges.length,
                        isAllMajor:
                            this.selectedMajors.length == this.initMajors.length,
                        college: college,
                        major: major,
                        leftMajor: this.initMajors,
                        term: this.postForm.term,
                        relationSelectCourse: this.postForm.relationSelectCourse
                    });
                    if (data.id) {
                        updateAuthPushTime(data).then(fn);
                    } else {
                        addAuthPushTime(data).then(fn);
                    }
                } else {
                    data.faculty = this.postForm.faculty.join(',');
                    data.authId = "231"
                    data.term = this.postForm.term
                    data.grade=this.postForm.grade.join(',')
                    data.trainingCategory = this.postForm.trainingCategory.join(',')
                    data.degreeType = this.postForm.degreeType.join(',')
                    data.formLearning = this.postForm.formLearning.join(',')
                    data.trainingLevel = this.postForm.trainingLevel.join(',')
                    data.courseApprove = this.postForm.courseApprove
                    data.planMaintain = this.postForm.planMaintain
                    data.startTime = this.postForm.startTime ? this.postForm.startTime.getTime() : ""
                    data.endTime = this.postForm.endTime ? this.postForm.endTime.getTime() : ""
                    //console.log(data.trainingCategory);
                    if (data.id) {
                        updateAuthTime(data).then(fn);
                    } else {
                        addAuthTime(data).then(fn);
                    }
                  //  this.initDialog()
                }
            });
        },
        //根据学院code获取专业集合
        getMajorsByColleges() {
            if (this.selectedColleges.length == 0) {
                this.initMajors = [];
                this.selectedMajors = [];
                return;
            }
            let data = [];
            this.selectedColleges.forEach(c => {
                data.push({
                    lang: this.$store.getters.language || "cn",
                    type: "allChild",
                    keys: ["G_ZY"],
                    filter: {
                        prefix: [c],
                        specilaCode: "XY2ZY"
                    }
                });
            });
            queryList(data).then(res => {
                if (res.code == 200) {
                    let majors = [];
                    res.data.forEach(c => {
                        for (let key in c) {
                            if (c[key]) {
                                let val = c[key];
                                if (val["G_ZY"]) {
                                    for (let majorKey in val["G_ZY"]) {
                                        majors.push({
                                            key: majorKey,
                                            label: val["G_ZY"][majorKey],
                                            pid: key
                                        });
                                    }
                                }
                            }
                        }
                    });
                    this.initMajors = majors;
                    this.selectedMajors = this.selectedMajors.filter(c => {
                        return majors.some(m_ => m_.key == c);
                    });
                }
            });
        },
        changeFaculty() {
            if (this.postForm.faculty.length && this.postForm.faculty.indexOf('all') > -1) {
                this.postForm.faculty = this.options.faculty.filter(item => item.value != 'all').map(i => i.value);
            }
        }
    }
};
</script>
<style lang="scss" scoped>
 .div-main {
        margin-bottom: 16px;
    }
</style>